package com.edu.exam.enums.questionbank;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 选项类型枚举
 */
public enum OptionType implements BaseEnum {
    TEXT("TEXT", "文本选项"),
    IMAGE("IMAGE", "图片选项"),
    AUDIO("AUDIO", "音频选项"),
    VIDEO("VIDEO", "视频选项"),
    MIXED("MIXED", "混合选项");

    private final String code;
    private final String description;

    OptionType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static OptionType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("OptionType code cannot be null or empty");
        }
        for (OptionType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown option type code: " + code);
    }

    public static OptionType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("OptionType description cannot be null or empty");
        }
        for (OptionType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown option type description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}